package com.salmon.scommerce.config;

import javax.inject.Inject;
import javax.sql.DataSource;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

@Configuration
@Import(DataSourceConfig.class)
public class MybatisConfig {

	@Inject DataSourceConfig dataSourceConfig;
	
	@Bean
	public SqlSessionFactoryBean getSqlSessionFactory(DataSource dataSource) {
		
		SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
		
		Resource resource  = new ClassPathResource("mybatis-config.xml");
		
		bean.setDataSource(dataSource);
		
		bean.setConfigLocation(resource);
		
		return bean;
	}
	
	@Bean MapperFactoryBean getAdminRoleMapper() {
		
		return null;
	}
}
